package com.seari.groovyrunner.service.impl;

import com.seari.groovyrunner.bean.GroovyTask;
import com.seari.groovyrunner.mapper.GroovyMapper;
import com.seari.groovyrunner.service.GroovyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("GroovyServiceImpl")
public class GroovyServiceImpl implements GroovyService {

    @Autowired
    private GroovyMapper mapper;

    
    @Override
    public List<GroovyTask> getTaskListByName(String taskName, String page, String limit) {
        Integer startIndex = (Integer.valueOf(page) - 1) * Integer.valueOf(limit);
        return mapper.getTaskListByName(taskName,startIndex.toString(),limit);
    }

    @Override
    public List<GroovyTask> getAllTaskList() {
        return mapper.getAllTaskList();
    }

    @Override
    public int addService(GroovyTask task) {
        ArrayList<GroovyTask> list = new ArrayList<>();
        list.add(task);
        return mapper.addGroovyTask(list);
    }

    @Override
    public int changeScriptStateById(int i, int id) {
        return mapper.changeScriptStateById(i,id);
    }

    @Override
    public List<GroovyTask> getTaskListByService(String service) {
        return mapper.getTaskListByService(service);
    }

    @Override
    public int updateService(GroovyTask task) {
        return mapper.updateGroovyTask(task);
    }

    @Override
    public int getTaskListCountByName(String taskName) {
        return mapper.getTaskListCountByName(taskName);
    }

    @Override
    public GroovyTask getTaskByID(Integer id) {
        return mapper.getTaskByID(id);
    }

    @Override
    public List<GroovyTask> getTaskListByPath(String path) {
        return mapper.getTaskListByPath(path);
    }

    @Override
    public int deleteTaskByID(Integer id) {
        return mapper.deleteGroovyTask(id);
    }
}
